package com.caregiver.watch.business.care.model.vo;

import com.caregiver.watch.business.care.helper.EcgHelper;
import com.caregiver.watch.business.user.enums.EcgAnalysisResultEnum;
import com.caregiver.watch.common.utils.collection.ListUtils;
import com.caregiver.watch.common.utils.time.DateUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalTime;
import java.util.List;

import static com.caregiver.watch.common.constant.NumberConstants.BIG_DECIMAL_TWO_THOUSAND;
import static com.caregiver.watch.common.constant.NumberConstants.FIVE;
import static com.caregiver.watch.common.constant.NumberConstants.TEN;
import static com.caregiver.watch.common.utils.time.DateUtils.HH_MM;

/**
 * @description: 心率详情数据
 * @program: caregiver-watch
 * @author: 疆戟
 * @create: 2025-10-03 15:29
 */
@Data
@Schema(description = "心率详情数据")
public class EcgDetailDataVo {

    @Schema(description = "心率详情数据")
    private List<EcgDetailData> ecgDetailData;

    public static EcgDetailDataVo build(List<EcgDetailData> ecgDetailData) {
        EcgDetailDataVo ecgDetailDataVo = new EcgDetailDataVo();
        ecgDetailDataVo.ecgDetailData = ecgDetailData;
        return ecgDetailDataVo;
    }

    @Data
    @Schema(description = "心率详情数据")
    public static class EcgDetailData {

        @Schema(description = "时间")
        private String time;

        @Schema(description = "心率值")
        private Integer heartRate;

        @Schema(description = "心电分析结果")
        private EcgAnalysisResultEnum ecgAnalysisResult;

        @Schema(description = "心率数据")
        private List<BigDecimal> ecg;


        public static EcgDetailData build(LocalTime time, Integer heartRate, EcgAnalysisResultEnum ecgAnalysisResult, List<BigDecimal> ecg) {
            EcgDetailData ecgDetailData = new EcgDetailData();
            ecgDetailData.time = DateUtils.format(time);
            ecgDetailData.heartRate = heartRate;
            ecgDetailData.ecgAnalysisResult = ecgAnalysisResult;
            ecgDetailData.ecg = EcgHelper.removeBaselineDrift(ecg, 50);
            return ecgDetailData;
        }
    }
}
